package com.sloth.bear.controller;

import com.sloth.bear.constant.CategoryType;
import com.sloth.bear.dto.request.CategoryRequest;
import com.sloth.bear.dto.request.DragRequest;
import com.sloth.bear.dto.vo.CategoryDetailsVo;
import com.sloth.bear.dto.vo.CategoryListVo;
import com.sloth.bear.service.CategoryService;
import lombok.RequiredArgsConstructor;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
public class CategoryController {

    private final CategoryService categoryService;

    /**
     * 创建分类
     */
    @PostMapping("/create")
    public CategoryDetailsVo createCategory(@RequestBody @Valid CategoryRequest request) {
        return categoryService.createCategory(request);
    }

    /**
     * 分类列表
     */
    @GetMapping("/list")
    public List<CategoryListVo> listCategory(@RequestParam CategoryType type) {
        return categoryService.listCategory(type);
    }

    /**
     * 获取分类详情
     */
    @GetMapping("/{id}")
    public CategoryDetailsVo detailsCategory(@PathVariable Long id) {
        return categoryService.detailsCategory(id);
    }

    /**
     * 更新分类
     */
    @PutMapping("/{id}")
    public void updateCategory(@PathVariable Long id, @RequestBody CategoryRequest request) {
        categoryService.updateCategory(id, request);
    }

    /**
     * 拖拽分类
     */
    @PutMapping("/{id}/drag")
    public void dropDoc(@PathVariable Long id, @RequestBody DragRequest request) {
        categoryService.drag(id, request);
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/{id}")
    public void deleteCategory(@PathVariable Long id) {
        categoryService.deleteCategory(id);
    }
}